const Router = require('koa-router')

const { auth } = require('../middleware/auth.middleware')

const { validator } = require('../middleware/order.middleware')

const { validateQuery } = require('../middleware/goods.middleware')

const { create, findAll, update } = require('../controller/order.controller')

const router = new Router({ prefix: '/orders' })

// 创建订单
router.post(
  '/',
  auth,
  validator({
    address_id: 'int',
    goods_info: 'string',
    total: 'string',
  }),
  create
)

// 获取订单列表
router.get('/', auth, validateQuery, findAll)

// 修改订单状态
router.patch(
  '/:id',
  auth,
  validator({ status: { type: 'number', required: true, min: 0 } }),
  update
)

module.exports = router
